﻿using System;
using System.Diagnostics;
using NetAssist.Collections;
using NetAssist.Diagnostics;
using NetAssist.Math;

namespace Samples
{
  class Program
  {
    static void Main(string[] args)
    {      
      try
      {
        Analyzer a;
        //      using (QuickStopwatch sw = new QuickStopwatch())
        // a = new Analyzer(new double[] { 6, 9, 14 });
        // a = new Analyzer(new double[] { 4, 9, 16 , 25, 50, 60});
        //a = new Analyzer((new double[] { -4, -9, -16 }));

        //  a = new Analyzer((new double[] { 5, 6 }));//,8,5,6,9,5,6,2,3,4,3,2,1,2,3,4,3,2,1 
        a = new Analyzer((new double[] { 3, 5, 7 }));//,8,5,6,9,5,6,2,3,4,3,2,1,2,3,4,3,2,1 
        //a = new Analyzer((new double[] { 3, 5, 7, 11 }));
        //a = new Analyzer((new double[] { 3, 5, 7, 11, 13 }));
        //a = new Analyzer((new double[] { 3, 5, 7, 11, 13, 17 }));
        //a = new Analyzer((new double[] { 3, 5, 7, 11, 13, 17, 19 }));
        //a = new Analyzer((new double[] { 3, 5, 7, 11, 13, 17, 19, 23 }));
        //a = new Analyzer((new double[] { 3, 5, 7, 11, 13, 17, 19, 23, 29 }));
        //a = new Analyzer((new double[] { 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 }));
        //a = new Analyzer((new double[] { 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37 }));
        //a = new Analyzer((new double[] { 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41 }));

        a = new Analyzer((new double[] { 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3 }));

        //a = new Analyzer((new double[] { 8, 32, 128, 312, 760, 1802, 4184 }));//,8,5,6,9,5,6,2,3,4,3,2,1,2,3,4,3,2,1 

        //a = new Analyzer((new double[] { 2, 4, 6, 8, 10, 12,14,16,18,20}));//,2,3,4,3,2,1,2,3,4,3,2,1 

        Debug.WriteLine(a.ToString());
      }
      catch (Exception)// ex)
      {


      }
    }

    static void Main2(string[] args)
    {
      ConsoleTraceListener consoleTracer = new ConsoleTraceListener();
      Trace.Listeners.Add(consoleTracer);

      do
      {

        Console.WriteLine("Select a Sample: ");
        Console.WriteLine("");
        Console.WriteLine(" 1) Buffer");
        Console.WriteLine(" 2) QuickStopwatch");
        Console.WriteLine(" Q) Quit");


        ConsoleKeyInfo response = Console.ReadKey(true);

        switch (response.KeyChar)
        {
          case '1':
            Console.WriteLine();
            BufferSample();
            break;
          case '2':
            Console.WriteLine();
            QuickStopwatchSample();
            break;
          case 'q':
          case 'Q':
            return;
          default:
            break;
        }
        Console.WriteLine("\r\n\r\nPress any key to continue.");
        Console.ReadKey();

        Console.Clear();
      } while (true);
    }

    private static void BufferSample()
    {
      Buffer<int> b = new Buffer<int>(4);

      b.Push(100);
      b.Push(200);
      b.Push(300);
      b.Push(400);
      b.Push(500);
      b.Push(600);

      var x1 = b[1];
      b.Pop();
      var x2 = b[1];

    }

    private static void QuickStopwatchSample()
    {
      string message = "Calculate 800K square roots";
      int roots = 800000;

      //Old way:
      System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
      sw.Start();
      CalcRoots(roots);
      sw.Stop();
      System.Diagnostics.Trace.WriteLine(string.Format("{0}: {1} (seconds)", message, sw.Elapsed.TotalSeconds));

      //Better way:
      using (QuickStopwatch qsw = new QuickStopwatch(message))
        CalcRoots(roots);
    }

    private static double CalcRoots(int rootsCount)
    {
      double sum = 0;
      for (int i = 0; i < rootsCount; i++)
        sum += Math.Sqrt(i);

      return sum;
    }
  }
}
